﻿import React from 'react';
import { Form, Input, Row, Col, Button, DatePicker,Icon, Select,Spin,Cascader } from 'antd';
import './index.less'
import classNames from 'classnames';
import { profileUpdate } from '../../actions'
import {connect} from 'react-redux'
import * as SelectTypes from '../../components/Form/CustomSelect';
import { majorData } from '../../assets/data/major'
import { region } from '../../assets/data/region'
const FormItem = Form.Item;
const Option = Select.Option;

class ProfileCard extends React.Component {
	constructor(props){
		super(props);
	}

	onNextClick(e) {
    e.preventDefault();
    this.props.form.validateFieldsAndScroll((errors, values) => {
      if (!!errors) {
        console.log('Errors in form!!!');
        return;
      }
      console.log('Submit!!!');
      let profile = {...values, homeplace:values.homeplace.join(','), majorName:values.majorName.join(',')};
      this.props.onNextClick(profile);
    });

  }

	render() {
    let { profile,loading } = this.props;
    const { getFieldDecorator } = this.props.form;
    let  { homeplace, majorName } = profile;
    if (profile.homeplace && typeof (profile.homeplace) == 'string') {
      homeplace = profile.homeplace.split(',');
    }
    if (profile.majorName && typeof (profile.homeplace) == 'string') {
      majorName = [profile.collegeName, profile.majorName];
    }

		const container = (
      <Form horizontal>
        <Row gutter={16}>
          <Col sm={1}>
          </Col>
          <Col sm={10}>
            <FormItem	label="学号"	labelCol={{ span: 8 }}	wrapperCol={{ span: 16 }} required>
              {getFieldDecorator('id', { initialValue: profile.id, rules: [{required: true}] })(<Input disabled  />)}
            </FormItem>
            <FormItem	label="性别"	labelCol={{ span: 8 }}	wrapperCol={{ span: 16 }} required>
              {getFieldDecorator('sex', { initialValue: profile.sex, rules: [{required: true}] })(<Input disabled />)}
            </FormItem>
            <FormItem	label="民族"	labelCol={{ span: 8 }}	wrapperCol={{ span: 16 }} required>
              {getFieldDecorator('nation', { initialValue: profile.nation, rules: [{required: true}] })(<Input disabled />)}
            </FormItem>
            <FormItem	label="籍贯"	labelCol={{ span: 8 }}	wrapperCol={{ span: 16 }} required>
              {getFieldDecorator('homeplace', { initialValue: homeplace, rules: [{required: true}] })(<Cascader options={region} expandTrigger="hover" />)}
            </FormItem>
            <FormItem	label="专业名称"	labelCol={{ span: 8 }}	wrapperCol={{ span: 16 }} required>
              {getFieldDecorator('majorName', { initialValue: majorName, rules: [{required: true}] })(<Cascader popupClassName="aaa" options={majorData} expandTrigger="hover" />)}
            </FormItem>
            <FormItem	label="学历"	labelCol={{ span: 8 }}	wrapperCol={{ span: 16 }} required>
              {getFieldDecorator('degree', { initialValue: profile.degree, rules: [{required: true}] })(SelectTypes.DegreeSelect)}
            </FormItem>
            <FormItem	label="入学时间"	labelCol={{ span: 8 }}	wrapperCol={{ span: 16 }} required>
              {getFieldDecorator('enterDate', { initialValue: profile.enterDate, rules: [{required: true}] })(SelectTypes.YearSelect)}
            </FormItem>
            <FormItem	label="通讯地址"	labelCol={{ span: 8 }}	wrapperCol={{ span: 16 }} required>
              {getFieldDecorator('address', { initialValue: profile.address, rules: [{required: true}] })(<Input  />)}
            </FormItem>
            <FormItem	label="联系电话"	labelCol={{ span: 8 }}	wrapperCol={{ span: 16 }} required>
              {getFieldDecorator('telephone', { initialValue: profile.telephone, rules: [{required: true}] })(<Input />)}
            </FormItem>
            <FormItem	label="就业协议号"	labelCol={{ span: 8 }}	wrapperCol={{ span: 16 }} required>
              {getFieldDecorator('employCode', { initialValue: profile.employCode, rules: [{required: true}] })(<Input />)}
            </FormItem>

            <FormItem	label="微信"	labelCol={{ span: 8 }}	wrapperCol={{ span: 16 }}>
              {getFieldDecorator('wxCode', { initialValue: profile.wxCode })(<Input />)}
            </FormItem>

          </Col>
          <Col sm={10}>
            <FormItem	label="姓名"	labelCol={{ span: 8 }}	wrapperCol={{ span: 16 }} required>
              {getFieldDecorator('name', { initialValue: profile.name, rules: [{required: true}] })(<Input disabled  />)}
            </FormItem>
            <FormItem	label="出生年月"	labelCol={{ span: 8 }}	wrapperCol={{ span: 16 }} required>
              {getFieldDecorator('birthday', { initialValue: profile.birthday, rules: [{required: true}] })(<Input disabled  />)}
            </FormItem>
            <FormItem	label="政治面貌"	labelCol={{ span: 8 }}	wrapperCol={{ span: 16 }} required>
              {getFieldDecorator('political', { initialValue: profile.political, rules: [{required: true}] })(SelectTypes.PoliticalSelect)}
            </FormItem>
            <FormItem	label="手机号码"	labelCol={{ span: 8 }}	wrapperCol={{ span: 16 }}>
              {getFieldDecorator('mobile', { initialValue: profile.mobile, rules: [{required: true}] })(<Input  />)}
            </FormItem>
            <FormItem	label="外语语种"	labelCol={{ span: 8 }}	wrapperCol={{ span: 16 }} required>
              {getFieldDecorator('foreignLanguage', { initialValue: profile.foreignLanguage, rules: [{required: true}] })(SelectTypes.LanguageSelect)}
            </FormItem>
            <FormItem	label="学制"	labelCol={{ span: 8 }}	wrapperCol={{ span: 16 }} required>
              {getFieldDecorator('studyLife', { initialValue: profile.studyLife, rules: [{required: true}] })(SelectTypes.StudyLifeSelect)}
            </FormItem>
            <FormItem	label="毕业时间"	labelCol={{ span: 8 }}	wrapperCol={{ span: 16 }} required>
              {getFieldDecorator('outDate', { initialValue: profile.outDate, rules: [{required: true}] })(SelectTypes.YearSelect)}
            </FormItem>
            <FormItem	label="邮政编码"	labelCol={{ span: 8 }}	wrapperCol={{ span: 16 }} required>
              {getFieldDecorator('zipCode', { initialValue: profile.zipCode, rules: [{required: true}] })(<Input />)}
            </FormItem>
            <FormItem	label="应聘方式"	labelCol={{ span: 8 }}	wrapperCol={{ span: 16 }} required>
              {getFieldDecorator('applyType', { initialValue: profile.applyType, rules: [{required: true}] })(SelectTypes.ApplyTypeSelect)}
            </FormItem>
            <FormItem	label="QQ"	labelCol={{ span: 8 }}	wrapperCol={{ span: 16 }}>
              {getFieldDecorator('qq', { initialValue: profile.qq })(<Input />)}
            </FormItem>

            <FormItem	label="电子邮箱"	labelCol={{ span: 8 }}	wrapperCol={{ span: 16 }} >
              {getFieldDecorator('email', { initialValue: profile.email })(<Input  />)}
            </FormItem>
          </Col>
          <Col sm={3}>
          </Col>
        </Row>
        <Row type="flex" justify="center">
          <Button type="primary" onClick={this.onNextClick.bind(this)}>下一步</Button>
          &nbsp;&nbsp;&nbsp;
          <Button disabled>上一步</Button>
        </Row>
      </Form>
		);
    return (
      <Spin spinning={loading}>{container}</Spin>
    );
	}
}

ProfileCard = Form.create()(ProfileCard);

export default ProfileCard;
